package com.example.writting.ui.cases

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.writting.data.CaseDataManager
import com.example.writting.databinding.FragmentCaseDetailBinding

class CaseDetailFragment : Fragment() {

    private var _binding: FragmentCaseDetailBinding? = null
    private val binding get() = _binding!!
    private lateinit var caseDataManager: CaseDataManager

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentCaseDetailBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        caseDataManager = CaseDataManager(requireContext())
        loadCaseDetails()
    }

    private fun loadCaseDetails() {
        val caseId = arguments?.getString("caseId") ?: return
        val caseData = caseDataManager.getCaseData(caseId)
        caseData?.let { data ->
            binding.tvSource.text = data.getString("source")
            binding.tvTitle.text = data.getString("title")
            binding.tvContent.text = data.getString("content")
            binding.tvQuestion.text = data.getString("question")
            binding.tvAnswer.text = data.getString("answer")
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
} 